<html>
<head><meta charset="utf-8"><title>mutating non-mutable statics: UB? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html">mutating non-mutable statics: UB?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="173201515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173201515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173201515">(Aug 14 2019 at 13:20)</a>:</h4>
<p>static FOO: u32 = 0;<br>
let ptr = &amp;FOO as *const u32 as *mut u32; <br>
*ptr += 1;</p>
<p>is this distinctly UB, or does this just this fall out of rules for references? Or do we guarantee a safe crash, relying on the static being stuffed in rodata so that mutations cause page faults (in the same way that we rely on the stack's guard page to guarantee stack overflows are safe)?</p>



<a name="173201592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173201592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173201592">(Aug 14 2019 at 13:20)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> ^</p>



<a name="173202451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202451">(Aug 14 2019 at 13:29)</a>:</h4>
<p>you are probably invoking UB before actually writing to the read-only memory</p>



<a name="173202484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202484">(Aug 14 2019 at 13:29)</a>:</h4>
<p>by doing a write through a pointer derived from a <code>&amp;T</code></p>



<a name="173202630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202630">(Aug 14 2019 at 13:30)</a>:</h4>
<p>if we get &amp;raw that won't be necessary anymore</p>



<a name="173202751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202751">(Aug 14 2019 at 13:31)</a>:</h4>
<p>naively it should be easy/fine to just guarantee an abort, just like with stackoverflow, but I don't know enough about linkers and exotic platforms to know if there's nightmares. Or if llvm makes it too hard to say "no really this is defined it's fine"</p>



<a name="173202821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202821">(Aug 14 2019 at 13:32)</a>:</h4>
<p>writing to read-only memory is UB in the abstract machine</p>



<a name="173202846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202846">(Aug 14 2019 at 13:32)</a>:</h4>
<p>is that written anywhere?</p>



<a name="173202905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202905">(Aug 14 2019 at 13:33)</a>:</h4>
<p>also what is our definition of read-only memory. I do not expect the abstract machine to have a notion of like, OS pages. Does it literally only arise from immutable statics?</p>



<a name="173202913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202913">(Aug 14 2019 at 13:33)</a>:</h4>
<p>in the reference</p>



<a name="173202926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202926">(Aug 14 2019 at 13:33)</a>:</h4>
<p>read-only memory is memory that can only be read from</p>



<a name="173202942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202942">(Aug 14 2019 at 13:33)</a>:</h4>
<p>it doesn't really matter whether it is put on read-write memory on the actual hardware or not</p>



<a name="173202954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173202954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173202954">(Aug 14 2019 at 13:33)</a>:</h4>
<p>it is read-only in the abstract machine</p>



<a name="173203011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203011">(Aug 14 2019 at 13:34)</a>:</h4>
<p>if you want to avoid that, you can use interior mutability</p>



<a name="173203014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203014">(Aug 14 2019 at 13:34)</a>:</h4>
<p>right so how does one declare readonly memory?</p>



<a name="173203023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203023">(Aug 14 2019 at 13:34)</a>:</h4>
<p>just statics?</p>



<a name="173203041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203041">(Aug 14 2019 at 13:34)</a>:</h4>
<p>declare/acquire</p>



<a name="173203042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203042">(Aug 14 2019 at 13:34)</a>:</h4>
<p><code>static FOO: T;</code> where <code>T</code> does not use interior mutability</p>



<a name="173203067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203067">(Aug 14 2019 at 13:34)</a>:</h4>
<p>can you answer my question directly yes/no?</p>



<a name="173203089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203089">(Aug 14 2019 at 13:35)</a>:</h4>
<p>i did answer it, it depends on the value that you put in the static</p>



<a name="173203117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203117">(Aug 14 2019 at 13:35)</a>:</h4>
<p><code>static FOO: AtomicU32;</code> can be mutated, so it cannot be in read-only memory, but <code>static BAR: u32</code> cannot be mutated, so it can be</p>



<a name="173203144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203144">(Aug 14 2019 at 13:35)</a>:</h4>
<p>i am asking if there's any way <em>other</em> than statics to get immutable memory</p>



<a name="173203163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203163">(Aug 14 2019 at 13:35)</a>:</h4>
<p>probably</p>



<a name="173203211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203211">(Aug 14 2019 at 13:36)</a>:</h4>
<p>you can ask the OS for some pages, write to them, and make them read only</p>



<a name="173203234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203234">(Aug 14 2019 at 13:36)</a>:</h4>
<p>so OS pages are part of the abstract machine?</p>



<a name="173203237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203237">(Aug 14 2019 at 13:36)</a>:</h4>
<p>no</p>



<a name="173203252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203252">(Aug 14 2019 at 13:36)</a>:</h4>
<p>or not yet</p>



<a name="173203262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203262">(Aug 14 2019 at 13:36)</a>:</h4>
<p>how does the model know/care that pages are readonly, then?</p>



<a name="173203272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203272">(Aug 14 2019 at 13:36)</a>:</h4>
<p>it doesn't know about that</p>



<a name="173203287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203287">(Aug 14 2019 at 13:37)</a>:</h4>
<p>so the abstract machine assumes they are all writable</p>



<a name="173203308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203308">(Aug 14 2019 at 13:37)</a>:</h4>
<p>only for certain statics and other things can it assume that you are never writing to the memory</p>



<a name="173203341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203341">(Aug 14 2019 at 13:37)</a>:</h4>
<p>e.g. <code>let x = 0_i32</code> puts an <code>i32</code> in memory that cannot be written to</p>



<a name="173203389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203389">(Aug 14 2019 at 13:38)</a>:</h4>
<p>in the abstract machine</p>



<a name="173203459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203459">(Aug 14 2019 at 13:39)</a>:</h4>
<p>what happens in actual hardware doesn't really matter</p>



<a name="173203476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203476">(Aug 14 2019 at 13:39)</a>:</h4>
<p>rust will optimize under the assumption that you don't mutate immutable memory</p>



<a name="173203479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203479">(Aug 14 2019 at 13:39)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span>  for <code>static</code>s there's a <code>Freeze</code> trait in the compiler</p>



<a name="173203495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203495">(Aug 14 2019 at 13:39)</a>:</h4>
<p>ok so if i memmap in a readonly page and write to it, is that "safe" or...?</p>



<a name="173203588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203588">(Aug 14 2019 at 13:40)</a>:</h4>
<p>depends on what mmap says about doing that</p>



<a name="173203599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203599">(Aug 14 2019 at 13:41)</a>:</h4>
<p>its an FFI function, with its own semantics, and it tells you what's safe or not</p>



<a name="173203611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203611">(Aug 14 2019 at 13:41)</a>:</h4>
<p>if it tells you that you can do that, then you can do it</p>



<a name="173203626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203626">(Aug 14 2019 at 13:41)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span> <a href="https://github.com/rust-lang/rust/blob/d19a359444295bab01de7ff44a9d72302e573bc9/src/libcore/marker.rs#L592-L604" target="_blank" title="https://github.com/rust-lang/rust/blob/d19a359444295bab01de7ff44a9d72302e573bc9/src/libcore/marker.rs#L592-L604">https://github.com/rust-lang/rust/blob/d19a359444295bab01de7ff44a9d72302e573bc9/src/libcore/marker.rs#L592-L604</a></p>



<a name="173203699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203699">(Aug 14 2019 at 13:42)</a>:</h4>
<p>types that implement Freeze _can_ be put in read-only memory when used in statics</p>



<a name="173203723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203723">(Aug 14 2019 at 13:42)</a>:</h4>
<p>yes that's not interesting and i understand</p>



<a name="173203752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203752">(Aug 14 2019 at 13:43)</a>:</h4>
<p>whether they will actually be put in read-only memory is something that's not guaranteed, it would depend on the target (does it support that?)</p>



<a name="173203764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203764">(Aug 14 2019 at 13:43)</a>:</h4>
<p>but from Rust point-of-view, you cannot mutate them either way</p>



<a name="173203823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203823">(Aug 14 2019 at 13:44)</a>:</h4>
<p>(I think we should consider exposing <code>Freeze</code>)</p>



<a name="173203861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203861">(Aug 14 2019 at 13:44)</a>:</h4>
<p>in case it wasn't clear this is Gankro i just changed my name, i am working on the page in the rustonomicon enumerating all the distinct classes of UB</p>



<a name="173203881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203881">(Aug 14 2019 at 13:45)</a>:</h4>
<p>(feeling like I'm being talked down to...)</p>



<a name="173203934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173203934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173203934">(Aug 14 2019 at 13:45)</a>:</h4>
<blockquote>
<p>(I think we should consider exposing Freeze)</p>
</blockquote>
<p><span class="user-mention" data-user-id="126931">@centril</span> what problem would that solve that can't be solved with UnsafeCell&lt;T&gt; ?</p>



<a name="173204088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204088">(Aug 14 2019 at 13:47)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> let's start a new thread bout that</p>



<a name="173204381"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204381" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204381">(Aug 14 2019 at 13:50)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span> I'd just mention writing to immutable memory as the form of UB</p>



<a name="173204450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204450">(Aug 14 2019 at 13:51)</a>:</h4>
<p>or maybe through an immutable binding</p>



<a name="173204489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204489">(Aug 14 2019 at 13:51)</a>:</h4>
<p>i can't do that without a clear definition of what "immutable memory" means. specifically this can very easily cause misconceptions around memmap and what the language supports wrt faults</p>



<a name="173204551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204551">(Aug 14 2019 at 13:52)</a>:</h4>
<p>memmap and faults are properties of a target/platform</p>



<a name="173204570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204570">(Aug 14 2019 at 13:52)</a>:</h4>
<p>i don't think we guarantee anywhere that if you write to read-only memory you get a diagnostic</p>



<a name="173204590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204590">(Aug 14 2019 at 13:52)</a>:</h4>
<p>in the same way that we can't guarantee that for, e.g., if you overflow the stack</p>



<a name="173204596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204596">(Aug 14 2019 at 13:52)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span> I'd say it's better to be conservative and say that more things are not allowed than might be for now</p>



<a name="173204644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204644">(Aug 14 2019 at 13:53)</a>:</h4>
<p>as far as i can tell, independently of the different ways that there are of creating immutable memory, all of them let you only access it from <code>&amp;T</code></p>



<a name="173204645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204645">(Aug 14 2019 at 13:53)</a>:</h4>
<p>i agree and that's usually the philosophy of the nomicon, but this is a case where there are very real systems programming patterns at stake here, and not just weird trivia</p>



<a name="173204661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204661">(Aug 14 2019 at 13:53)</a>:</h4>
<p>so the real UB is writing through an &amp;T</p>



<a name="173204698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204698">(Aug 14 2019 at 13:53)</a>:</h4>
<p>as a concrete example, someone was adding asserts that we don't mutate the empty singleton, and I said they shouldn't bother because it will fault</p>



<a name="173204752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204752">(Aug 14 2019 at 13:54)</a>:</h4>
<p>(empty hashmap singleton)</p>



<a name="173204754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204754">(Aug 14 2019 at 13:54)</a>:</h4>
<p>e.g. <code>let mut x = 0; let x = x; *(&amp;x as *mut) = 3;</code> is UB, it doesn't really matter whether the x is in rw or ro memory</p>



<a name="173204797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204797">(Aug 14 2019 at 13:54)</a>:</h4>
<p>the case of using raw is really worth addressing though</p>



<a name="173204803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204803">(Aug 14 2019 at 13:54)</a>:</h4>
<p>yeah that falls out of the pointer aliasing rules, statics with &amp;raw introduce a distinct class of UB</p>



<a name="173204807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204807">(Aug 14 2019 at 13:54)</a>:</h4>
<p>yep</p>



<a name="173204834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204834">(Aug 14 2019 at 13:55)</a>:</h4>
<p>I don't think anybody has mentioned this in the &amp;raw RFC</p>



<a name="173204850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204850">(Aug 14 2019 at 13:55)</a>:</h4>
<p>without <code>&amp;raw</code> we don't really need to talk about ro or rw memory</p>



<a name="173204885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173204885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173204885">(Aug 14 2019 at 13:55)</a>:</h4>
<p>only say that writes through &amp;T are not allowed unless T uses interior mutability</p>



<a name="173205013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173205013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173205013">(Aug 14 2019 at 13:57)</a>:</h4>
<p>(and as long as there aren't any data-races, etc.)</p>



<a name="173205048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173205048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173205048">(Aug 14 2019 at 13:57)</a>:</h4>
<p>with <code>&amp;raw</code> you can create a raw pointer directly to a memory location without going through a <code>&amp;T</code> and raw pointers don't really have these rules</p>



<a name="173205063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173205063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173205063">(Aug 14 2019 at 13:57)</a>:</h4>
<p>idk, feels like RFC material</p>



<a name="173205127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173205127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173205127">(Aug 14 2019 at 13:58)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span>  it's probably best noted on the rfc</p>



<a name="173217153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217153">(Aug 14 2019 at 16:08)</a>:</h4>
<blockquote>
<p>i am asking if there's any way <em>other</em> than statics to get immutable memory</p>
</blockquote>
<p>you could count const promotion, but that's basically anonymous statics</p>



<a name="173217288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217288">(Aug 14 2019 at 16:10)</a>:</h4>
<blockquote>
<p>as a concrete example, someone was adding asserts that we don't mutate the empty singleton, and I said they shouldn't bother because it will fault</p>
</blockquote>
<p>we certainly don't <em>guarantee</em> a fault when writing to immutable memory</p>



<a name="173217316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217316">(Aug 14 2019 at 16:10)</a>:</h4>
<p>I'd say kernel allocations / mmap / ...  are outside of what the abstract machine can talk about. but we can add a notion of "read-only allocation" to the abstract machine. Miri has that in fact.</p>



<a name="173217336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217336">(Aug 14 2019 at 16:11)</a>:</h4>
<p>that said, this notion is not needed with stacked borrows: the original code up there has UB because it writes through a (pointer derived from) a shared reference</p>



<a name="173217374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217374">(Aug 14 2019 at 16:11)</a>:</h4>
<p><code>&amp;raw</code> doesnt change that either, like <code>as *const T</code> it, too, produces a read-only pointer (except for interior mutability of course)</p>



<a name="173217504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217504">(Aug 14 2019 at 16:13)</a>:</h4>
<p>Also see <a href="https://github.com/rust-lang/rust/issues/56604" target="_blank" title="https://github.com/rust-lang/rust/issues/56604">https://github.com/rust-lang/rust/issues/56604</a> for the fact that right now, <code>as *mut T</code> and <code>as *const T as *mut T</code> are <em>not</em> the same</p>



<a name="173217506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173217506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173217506">(Aug 14 2019 at 16:13)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span> ^</p>



<a name="173220101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220101">(Aug 14 2019 at 16:45)</a>:</h4>
<p>ah ok, so the distinction of <code>&amp;raw</code> and <code>&amp;raw mut</code> is actually important and not just a jank artifact of *mut and *const</p>



<a name="173220222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220222">(Aug 14 2019 at 16:46)</a>:</h4>
<p>(haven't actually read through the &amp;raw proposal properly, mostly just assumed its content is obvious, since it's just there to fill a weird semantic hole we have)</p>



<a name="173220262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220262">(Aug 14 2019 at 16:46)</a>:</h4>
<blockquote>
<p>ah ok, so the distinction of <code>&amp;raw</code> and <code>&amp;raw mut</code> is actually important and not just a jank artifact of *mut and *const</p>
</blockquote>
<p>for Stacked Borrows right now it is. some would call that a bug.</p>



<a name="173220294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220294">(Aug 14 2019 at 16:47)</a>:</h4>
<p>but maybe it's actually reasonable.</p>



<a name="173220320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220320">(Aug 14 2019 at 16:47)</a>:</h4>
<p>that does certainly mess up the counter-proposal i was mulling</p>



<a name="173220334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220334">(Aug 14 2019 at 16:47)</a>:</h4>
<p>well, "right now" isn't fair as <code>&amp;[mut] raw</code> is not implemented -- but there is a difference between <code>x as *const T</code> and <code>x as *mut T</code>, and I think the same would happen with the raw-ref operator</p>



<a name="173220406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220406">(Aug 14 2019 at 16:48)</a>:</h4>
<p>huh? really?</p>



<a name="173220416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220416">(Aug 14 2019 at 16:48)</a>:</h4>
<p>i agree that that feels like a bug at first blush :)</p>



<a name="173220422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220422">(Aug 14 2019 at 16:48)</a>:</h4>
<p>the borrow checker treats them differently</p>



<a name="173220446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220446">(Aug 14 2019 at 16:48)</a>:</h4>
<p>x is &amp;mut T here?</p>



<a name="173220451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220451">(Aug 14 2019 at 16:48)</a>:</h4>
<p>yes</p>



<a name="173220499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220499">(Aug 14 2019 at 16:49)</a>:</h4>
<p>so to make Stacked Borrows, as it was designed to be, a dynamic version of the borrow checker, I saw no choice but also treat them differently in Stacked Borrows. it is rather nice in terms of model simplicity, but it looks strange when seen from the surface language.</p>



<a name="173220509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220509">(Aug 14 2019 at 16:49)</a>:</h4>
<p>so basically as *const T acts <em>as if</em> it implicitly also contained <code>as &amp;T</code> as a prefix?</p>



<a name="173220529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220529">(Aug 14 2019 at 16:49)</a>:</h4>
<p>see <a href="https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315" target="_blank" title="https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315">https://github.com/rust-lang/rust/issues/56604#issuecomment-477954315</a> for all the details, seems silly for me to type that all again^^</p>



<a name="173220538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220538">(Aug 14 2019 at 16:49)</a>:</h4>
<blockquote>
<p>so basically as *const T acts <em>as if</em> it implicitly also contained <code>as &amp;T</code> as a prefix?</p>
</blockquote>
<p>yes</p>



<a name="173220597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220597">(Aug 14 2019 at 16:50)</a>:</h4>
<p>for borrow checking and Stacked Borrows alike</p>



<a name="173220620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220620">(Aug 14 2019 at 16:50)</a>:</h4>
<p>hmm, so that definitely doesn't inherently motivate that behaviour for &amp;raw</p>



<a name="173220641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220641">(Aug 14 2019 at 16:50)</a>:</h4>
<p>it suggests it's worth considering though</p>



<a name="173220731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220731">(Aug 14 2019 at 16:51)</a>:</h4>
<p>but i would probably need to spend several days familiarizing myself with the currently proposed rules for what you can do with a raw pointer :s</p>



<a name="173220783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220783">(Aug 14 2019 at 16:52)</a>:</h4>
<p>from a Stacked Borrows lense it does motivate that quite directly ;)</p>



<a name="173220802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220802">(Aug 14 2019 at 16:52)</a>:</h4>
<p>the action of a "raw const reborrow" already exists there, and is used for <code>as *const T</code> casts</p>



<a name="173220813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220813">(Aug 14 2019 at 16:52)</a>:</h4>
<p>I'd just use that same action for <code>&amp;raw</code></p>



<a name="173220826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220826">(Aug 14 2019 at 16:52)</a>:</h4>
<p>and, specifically, that action creates read-only pointers (modulo <code>UnsafeCell</code>)</p>



<a name="173220847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220847">(Aug 14 2019 at 16:52)</a>:</h4>
<p>ugh, what an ugly language wart</p>



<a name="173220871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220871">(Aug 14 2019 at 16:53)</a>:</h4>
<p>it's actually less ugly in some sense than what I did before when It treated them the same^^</p>



<a name="173220890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220890">(Aug 14 2019 at 16:53)</a>:</h4>
<blockquote>
<p>but i would probably need to spend several days familiarizing myself with the currently proposed rules for what you can do with a raw pointer :s</p>
</blockquote>
<p>organizational question: that's mostly orthogonal to what my PR does, right?</p>



<a name="173220895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220895">(Aug 14 2019 at 16:53)</a>:</h4>
<p>like, <code>&amp;raw</code> isnt going to be stable for quite a while</p>



<a name="173220950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220950">(Aug 14 2019 at 16:54)</a>:</h4>
<p>yeah we can ignore the question for now</p>



<a name="173220962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220962">(Aug 14 2019 at 16:54)</a>:</h4>
<p>and given the current level of details on aliasing rules in there, I think we can fudge this together with that</p>



<a name="173220964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220964">(Aug 14 2019 at 16:54)</a>:</h4>
<p>although, it does seem quite important to the raw RFC</p>



<a name="173220967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220967">(Aug 14 2019 at 16:54)</a>:</h4>
<p>we can always refine this later</p>



<a name="173220986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173220986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173220986">(Aug 14 2019 at 16:54)</a>:</h4>
<blockquote>
<p>although, it does seem quite important to the raw RFC</p>
</blockquote>
<p>the problem being that the aliasing stuff is <em>so far</em> away from RFC-ready...</p>



<a name="173221034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173221034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173221034">(Aug 14 2019 at 16:55)</a>:</h4>
<p>I think the question about <code>&amp;raw</code> and about casts should have consistent answers anyway</p>



<a name="173221048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173221048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173221048">(Aug 14 2019 at 16:55)</a>:</h4>
<p>(in fact I will lobby to remove ref-to-raw casts from MIR and desugar them to raw reborrows)</p>



<a name="173221089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173221089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173221089">(Aug 14 2019 at 16:55)</a>:</h4>
<p>so really this was quite important when <code>as *const T</code> was introduced to the language, the question doesn't change much with <code>&amp;raw</code> IMO</p>



<a name="173221514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173221514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173221514">(Aug 14 2019 at 17:00)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> i'm not sure I agree with your assessment in the linked comment that we need to appeal to the cast/coercion being performed. One can understand it as a lint, like the rest of *mut vs *const. Is there anything wrong with proposing a model where a pointer only has permissions equivalent to the reference it was derived from? In this case yes we are deriving from an &amp;mut, but it's not a "real" &amp;mut, it's one in "shared reference" mode. does that make sense?</p>



<a name="173221865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173221865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173221865">(Aug 14 2019 at 17:04)</a>:</h4>
<p>(full disclosure, I intend in the fullness of time to push for a third *T type (~equivalent to today's ptr::NonNull), with the intent that everyone should eventually stop using <code>*const</code>/<code>*mut</code>, and everything should work fine, so it's a bit distressing to find a case where *const vs *mut is treated as meaningful)</p>



<a name="173226050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173226050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173226050">(Aug 14 2019 at 17:56)</a>:</h4>
<blockquote>
<p>Is there anything wrong with proposing a model where a pointer only has permissions equivalent to the reference it was derived from?</p>
</blockquote>
<div class="codehilite"><pre><span></span>let x = &amp;mut 0;
let shared = &amp;*x;
let y: *const i32 = x;
let _val = *shared;
unsafe { *(y as *mut i32) = 1; }
</pre></div>


<p>is this UB?<br>
this code stops compiling if you make <code>y: *mut T</code>. and making this code fine as-written would require significant re-architecting of stacked borrows. not saying that says we shouldn't do it, just saying that there is some way in which this is inherently more complicated than everything else stacked borrows does.</p>



<a name="173226122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173226122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173226122">(Aug 14 2019 at 17:57)</a>:</h4>
<p><span class="user-mention" data-user-id="137587">@Gankra</span>  "new permissions depend on old permission" is kind of complicated, in the sense that "old permission" can differ per-location. it also makes code harder to reason about, both for users and compilers.</p>



<a name="173226213"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173226213" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173226213">(Aug 14 2019 at 17:58)</a>:</h4>
<p>but yes, this is what Stacked Borrows 1.0 did</p>



<a name="173226225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173226225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173226225">(Aug 14 2019 at 17:58)</a>:</h4>
<p>but when Stacked Borrows 2 did more precise tracking for shared references, that didn't work any more</p>



<a name="173227889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173227889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173227889">(Aug 14 2019 at 18:15)</a>:</h4>
<p>I agree the const/mut distinction here is a useful way for you to write code that doesn't compile if you fuck it up, as I agree it can be difficult to reason about when shared loans expire. It is not however clear to me that we actually <em>need</em> the cast to be the thing that specifically acquires a particular permission, instead of the permission just getting "snapshot" at the point where the  cast occurs. That said, I am starting to think that this doesn't make sense, as we now have non-lexical borrows, and so permission is explicitly driven by use. It could be that <code>as *mut</code> vs <code>as *const</code> specifically needs to be significant for purpose of extending borrow liveness. Not sure.</p>



<a name="173228093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228093">(Aug 14 2019 at 18:17)</a>:</h4>
<p>hm. interesting thought.</p>



<a name="173228229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228229">(Aug 14 2019 at 18:18)</a>:</h4>
<p>This might also still actually jive okayish with my pointer unification proposal, if I make very precise tweeks to it.</p>



<a name="173228435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228435">(Aug 14 2019 at 18:21)</a>:</h4>
<p>hmm, no you can't reasonably have const/mut decay to a unified *T as a coercion (as if they only really exist for the purposes of casts), because that would be asserting non-nullness as a coercion</p>



<a name="173228565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228565">(Aug 14 2019 at 18:22)</a>:</h4>
<p>would have to be <code>unsafe { ... }</code></p>



<a name="173228595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228595">(Aug 14 2019 at 18:23)</a>:</h4>
<p>too easy to miss in a swamp of unsafe code</p>



<a name="173228661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228661">(Aug 14 2019 at 18:24)</a>:</h4>
<p>that's why I think unsafe blocks should be as narrowly scoped as possible <span aria-label="slight smile" class="emoji emoji-1f642" role="img" title="slight smile">:slight_smile:</span></p>



<a name="173228737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173228737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173228737">(Aug 14 2019 at 18:24)</a>:</h4>
<p>(also just to be 100% clear on the example I gave about removing assertions on the assumption that mutating the static will crash: they were just intended as debug assertions to catch bugs more immediately)</p>



<a name="173229257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173229257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173229257">(Aug 14 2019 at 18:31)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> can anything go wrong if you accidentally have too much raw pointer permission? Does there exist a program under your model that is totally sound with <code>as *const</code>, but UB with <code>as *mut</code>, assuming literally every other line of code is the same? I should think not, right?</p>



<a name="173229437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173229437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gankra <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173229437">(Aug 14 2019 at 18:32)</a>:</h4>
<p>unlike &amp;mut vs &amp;, it's just about a strict increase in permission, and not a trade of one permission for another? (shared ^ mut for references)</p>



<a name="173230607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173230607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173230607">(Aug 14 2019 at 18:46)</a>:</h4>
<blockquote>
<p>that's why I think unsafe blocks should be as narrowly scoped as possible :)</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rfcs/pull/2585" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2585">https://github.com/rust-lang/rfcs/pull/2585</a></p>



<a name="173230662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173230662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173230662">(Aug 14 2019 at 18:47)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> can anything go wrong if you accidentally have too much raw pointer permission? Does there exist a program under your model that is totally sound with <code>as *const</code>, but UB with <code>as *mut</code>, assuming literally every other line of code is the same? I should think not, right?</p>
</blockquote>
<p>I would think not. this should be monotone.<br>
but this is subtle enough that I won't say anything definite without <del>my lawyer</del> a proof</p>



<a name="173230777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173230777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173230777">(Aug 14 2019 at 18:48)</a>:</h4>
<blockquote>
<p><a href="https://github.com/rust-lang/rfcs/pull/2585" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2585">https://github.com/rust-lang/rfcs/pull/2585</a></p>
</blockquote>
<p>(Yeah, I'm pro, but I'd also like <a href="https://github.com/Centril/rfcs/pull/17" target="_blank" title="https://github.com/Centril/rfcs/pull/17">https://github.com/Centril/rfcs/pull/17</a> in that case)</p>



<a name="173230878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173230878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173230878">(Aug 14 2019 at 18:49)</a>:</h4>
<blockquote>
<p>unlike &amp;mut vs &amp;, it's just about a strict increase in permission, and not a trade of one permission for another? (shared ^ mut for references)</p>
</blockquote>
<p>yeah. <code>*mut</code> is always <code>SharedReadWrite</code>; <code>*const</code> is either <code>SharedReadWrite</code> or <code>SharedReadOnly</code> depending on <code>UnsafeCell</code></p>



<a name="173235017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173235017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173235017">(Aug 14 2019 at 19:39)</a>:</h4>
<p>so IIUC a <code>usize as *const T as *mut T</code> that writes would be UB, but <code>usize as *mut T</code> might be ok ?</p>



<a name="173235033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173235033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173235033">(Aug 14 2019 at 19:40)</a>:</h4>
<p>what if the <code>usize</code> points to immutable memory, and I do <code>usize as *mut T</code> ?</p>



<a name="173235411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173235411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173235411">(Aug 14 2019 at 19:44)</a>:</h4>
<blockquote>
<p>what if the <code>usize</code> points to immutable memory, and I do <code>usize as *mut T</code> ?</p>
</blockquote>
<p><code>as *mut</code> is only allowed from an <code>&amp;mut</code>. so how do you do that?</p>



<a name="173235665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173235665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173235665">(Aug 14 2019 at 19:47)</a>:</h4>
<p><code>transmute</code> then</p>



<a name="173236204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236204">(Aug 14 2019 at 19:54)</a>:</h4>
<p>you will in the end have derived that pointer from an <code>&amp;</code></p>



<a name="173236212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236212">(Aug 14 2019 at 19:54)</a>:</h4>
<p>and that's UB</p>



<a name="173236219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236219">(Aug 14 2019 at 19:54)</a>:</h4>
<p>I don't think you can avoid that</p>



<a name="173236258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236258">(Aug 14 2019 at 19:55)</a>:</h4>
<p>makes sense</p>



<a name="173236275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236275">(Aug 14 2019 at 19:55)</a>:</h4>
<p>I thought one could do an <code>usize as *mut</code> without going through an <code>&amp;mut T</code></p>



<a name="173236287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236287">(Aug 14 2019 at 19:55)</a>:</h4>
<p>but how do you get the <code>usize</code>?</p>



<a name="173236338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236338">(Aug 14 2019 at 19:56)</a>:</h4>
<p>i think that if <code>&amp;raw</code> returns a pointer from which no pointers that can write can be obtained, then all is good</p>



<a name="173236343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236343">(Aug 14 2019 at 19:56)</a>:</h4>
<p>at this point the result heavily depends on lots of details -- without an executable example program, the answer will always be "it depends"^^</p>



<a name="173236354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236354">(Aug 14 2019 at 19:56)</a>:</h4>
<p>if you have an static variable, the usize with its address can be another static</p>



<a name="173236367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236367">(Aug 14 2019 at 19:56)</a>:</h4>
<p>the linker can fill those appropriately (a bit of unnecessary, but bare with me)</p>



<a name="173236379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173236379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173236379">(Aug 14 2019 at 19:57)</a>:</h4>
<p>heh, pointers created by CTFE ;) I thought about that. no idea what the rules should be.</p>



<a name="173263656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173263656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173263656">(Aug 15 2019 at 03:58)</a>:</h4>
<blockquote>
<p>how do you get that <code>usize</code>?</p>
</blockquote>
<p>It could always be a fixed hardware address ;3</p>
<p>because you totally <em>can</em> write <code>*(0x0400_0000_usize as *mut u16).write_volatile(1);</code>, and however else you decide the rest of pointers works, Rust needs to support that sort of expression working on many targets of varying obscurity.</p>



<a name="173263805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173263805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173263805">(Aug 15 2019 at 04:03)</a>:</h4>
<p>of course, I think that having a 98% complete  memory model and saying "also the hardware is allowed to do its own extra things" is acceptable</p>



<a name="173263816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173263816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173263816">(Aug 15 2019 at 04:03)</a>:</h4>
<p>so "that's platform specific" is fine</p>



<a name="173273908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173273908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173273908">(Aug 15 2019 at 08:31)</a>:</h4>
<p>you are mixing "made-up" integer addresses and volatile. two complex subjects. yeah it'll be a bit until we get there. ;)</p>



<a name="173273922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating%20non-mutable%20statics%3A%20UB%3F/near/173273922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/mutating.20non-mutable.20statics.3A.20UB.3F.html#173273922">(Aug 15 2019 at 08:31)</a>:</h4>
<p>for "made-up" addresses, I think we can deal with them by making the Abstract Machine "open" -- it dos not assume total knowledge about which allocations exist in memory</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>